<template>
	<view class="uni_box home">
		<navbar title='发布项目'>
		</navbar>
		<view class="content">
			<view class="leiview">
				<view class="leiitem" @click="mpshow=true">
					<view class="shu"></view>
					<text class="name">项目类型<text class="xing">*</text></text>
					<view class="leiitem ml">
						<text class="xuan">{{ mpinfo.label?mpinfo.label:'请选择' }}</text>
						<image class="nav_icon_back" src="/static/img/nav_icon_back.png"></image>
					</view>
				</view>
			</view>
			<view class="leiview">
				<view class="leiitem oneitem">
					<view class="shu"></view>
					<text class="name">项目标题<text class="xing">*</text></text>
					<text class="zuiduo">好的标题能吸引更多用户查看</text>
				</view>
				<view class="leiitem twoinput">
					<u-input v-model="mpfabu.title" type="text" :border="false" placeholder="请输入"/>
				</view>
			</view>
			<view class="leiview">
				<view class="leiitem oneitem">
					<view class="shu"></view>
					<text class="name">详情描述<text class="xing">*</text></text>
					<text class="zuiduo hong">禁止发布黄赌毒、资金盘、诈骗等违规违法内容</text>
				</view>
				<view class="leiitem twoinput">
					<u-input v-model="mpfabu.descript" maxlength="10000" type="textarea" :border="false" placeholder="请输入"/>
				</view>
				<!-- <view class="leiitem">
					<view class="jiavx">
						<image class="icon_wx" src="/static/img/icon_wx.png"></image>
						<text>添加联系方式</text>
					</view>
					
				</view> -->
				
			</view>
			<!-- <view class="leiview">
				<view class="leiitem oneitem">
					<view class="shu"></view>
					<text class="name">联系方式<text class="xing">*</text></text>
				</view>
				<view class="leiitem twoinput">
					<u-input v-model="mpfabu.wechat" type="text" :border="false" placeholder="请输入"/>
				</view>
			</view> -->
			<view class="leiview">
				<view class="leiitem">
					<view class="shu"></view>
					<text class="name">添加图片<text class="xing">*</text></text>
					<text class="zuiduo">最多1张，首张封面显示。封面尺寸：240*240</text>
				</view>
				<view class="leiitem col buviewtwo">
					<view class="tuview">
						<view class="tuitem" @click="upload(1)" v-if="mpfabu.image.length<1">
							<image class="addtu" src="/static/img/btn_tupian.png"></image>
						</view>
						<view class="tuitem" v-for="(item,index) in mpfabu.image" :key="index">
							<view class="cha" @click="del(1,index)">
								<image class="shanicon" src="/static/img/shanicon.png"></image>
							</view>
							<image class="addtu" :src="item"></image>
						</view>
					</view>
				</view>
			</view>
			<view class="leiview">
				<view class="leiitem">
					<view class="shu"></view>
					<text class="name">添加详情图片</text>
					<text class="zuiduo">最多6张</text>
				</view>
				<view class="leiitem col buviewtwo">
					<view class="tuview">
						<view class="tuitem" @click="upload(3)" v-if="mpfabu.images.length<6">
							<image class="addtu" src="/static/img/btn_tupian.png"></image>
						</view>
						<view class="tuitem" v-for="(item,index) in mpfabu.images" :key="index">
							<view class="cha" @click="del(3,index)">
								<image class="shanicon" src="/static/img/shanicon.png"></image>
							</view>
							<image class="addtu" :src="item"></image>
						</view>
					</view>
				</view>
			</view>
			<!-- <view class="leiview">
				<view class="leiitem oneitem">
					<view class="shu"></view>
					<text class="name">播放位置</text>
					<text class="zuiduo hong">开通会员最高7折优惠</text>
				</view>
				<view class="renview">
					<view class="renitem">
						<view class="biaoqiantwo " :class="posinfo.id == item.id?'active':''" v-for="(item,index) in poslist" :key="index" @click="pClick(item)">
							<text class="biaoname">{{item.name}}</text>
							<image class="boitem" src="/static/img/boitem.png"></image>
							<image class="chagou" src="/static/img/chagou.png"></image>
						</view>
					</view>
				</view>
			</view> -->
			<view class="xieyi" @click.stop="isgou=!isgou">
				<image class="chagou" src="/static/img/zhigous.png" v-if="isgou"></image>
				<image class="chagou" src="/static/img/zhigou.png" v-if="!isgou"></image>
				<text class="tyiname">已阅读并同意<text class="xiename" @click.stop="yhxieyi">《用户发布协议》</text></text>
			</view>
		</view>

		<view class="botview">
			<text class="jinprice">支付金额：<text class="jinnum">{{ price }}</text></text>
			<view class="lianxi" :style="{
				background: zhucolor
			}" @click="shenqing">
				立即发布
			</view>
		</view>

		<!-- 时间选择 -->
		<u-calendar v-model="rilishow" :mode="mode" @change="richange"></u-calendar>

		<!-- 名片类型 -->
		<u-select v-model="mpshow" :list="mplist" @confirm="mpconfirm"></u-select>
	</view>
</template>

<script>
import {
		baseUrl
	} from '@/utils/config.js';
	export default {
		data() {
			return {
				phone:"",
				value: 0,
				mode:'date',
				rilishow:false,
				zhucolor: uni.getStorageSync('zhu_color'),
				mpfabu:{
					title:'',
					cid:'',
					descript:'',//简介
					// wechat:'',//微信
					image:[],//单图
					images:[],//示例图
					price:0
					// postion_id:'',//位置id
				},
				updatetype:1,//1头像 2二维码 3示例图
				headimg:'',

				mplist:[],//类型
				mpinfo:{},//类型选择
				mpshow:false,
				poslist:[],//位置
				posinfo:{},
				isgou:false,
				price:0,
				info:{}
			}
		},
		onLoad() {
			// quangetCate,
			// quangetPostion,
			// quanadd,
			this.getquangetCate();//类型
			// this.getquangetPostion();//位置
			this.fcardgetInit();//名片配置
			this.getuserinfo()
		},
		onShow() {
		},
		methods: {
			async getuserinfo(){
				let res = await this.$u.api.usergetData({
				});
				this.info = res
				// this.user = res.user
			},
			async fcardgetInit(){
				let res = await this.$u.api.quangetInit({
				});
				this.price = res.price
				this.mpfabu.price = res.price
			},
			async getquangetCate(){
				let res = await this.$u.api.quangetCate({
				});
				let shuzu = res
				for(let i in shuzu){
					shuzu[i].label = shuzu[i].name
					shuzu[i].value = shuzu[i].id
				}
				this.mplist = shuzu
			},
			async getquangetPostion(){
				let res = await this.$u.api.quangetPostion({
				});
				this.poslist = res
				if(res){
					this.posinfo = res[0]
					this.mpfabu.postion_id = this.posinfo.id
				}
			},	
			valChange(e) {
				console.log('当前值为: ' + e.value)
			},
			richange(e){
				console.log(e)
			},
			mpconfirm(e){
				console.log(e)
				this.mpinfo.label = e[0].label
				this.mpinfo.value = e[0].value
				this.mpfabu.cid = e[0].value
			},
			pClick(item){
				this.posinfo = item
				this.mpfabu.postion_id = this.posinfo.id
			},
			upload(e) {
				this.updatetype = e
				uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						this.headimg = tempFilePaths[0];
						// this.isClick = true;
						this.unloadtou()
						// this.getavatar();//修改信息
					}
				});
			},
			unloadtou(){
				// console.log(this.head_portrait)
				let that = this
				uni.uploadFile({
					// url: baseUrl + '/api/uploadImage', //仅为示例，非真实的接口地址
					url: baseUrl + '/common/upload', //仅为示例，非真实的接口地址
					filePath: this.headimg,
					name: 'file',
					header: {
						// 'content-type': 'application/json;charset=UTF-8',
						'token':uni.getStorageSync('token'),
					},
					formData: {
						'token':uni.getStorageSync('token'),
					},
					success: (uploadFileRes) => {
						// console.log( JSON.parse(uploadFileRes.data).data);
						let mpfabu = that.mpfabu
						if(that.updatetype==1){
							//名片
							mpfabu.image.push(JSON.parse(uploadFileRes.data).data.fullurl)
						}else if(that.updatetype==2){
							//二维码
							mpfabu.qrcode.push(JSON.parse(uploadFileRes.data).data.fullurl)
						}else if(that.updatetype==3){
							//示例图
							mpfabu.images.push(JSON.parse(uploadFileRes.data).data.fullurl)
						}
					}
				});
			},
			del(type,index){
				let mpfabu = this.mpfabu
				if(type == 1){
					mpfabu.image.splice(index,1)
				}else if(type ==2){
					mpfabu.qrcode.splice(index,1)
				}else if(type ==3){
					mpfabu.images.splice(index,1)
				}
				this.mpfabu = mpfabu
			},
			async shenqing(){
				if(!this.isgou){
					this.$u.toast("请先勾选协议");
					return false;
				}
				console.log(this.mpfabu)
				let parms = JSON.parse(JSON.stringify(this.mpfabu))
				// data =  JSON.parse(JSON.stringify(infolist))
				parms.images = parms.images.toString()
				parms.image = parms.image.toString()
				
				// if(Number(this.price)>Number(this.info.money)){
				// 	this.$u.toast("余额不足 请先进行充值");
				// 	setTimeout(() => {
				// 		this.navrouter("/pages_subject/twoPage/Chuzhi");
				// 	}, 1000);
				// 	return false;
				// }
				
				let res = await this.$u.api.quanadd(parms);
				this.$u.toast("操作成功");
				setTimeout(() => {
					uni.navigateBack()
				}, 1000);
			},
			yhxieyi(){
				this.navrouter("/pages/TPage/Xieyi?type=xmyhfbxy");
			}
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #fff;
	}
	.content{
		min-height: 100vh;
		background-color: #f5f5f5;
		padding: 20rpx 0 150rpx;
		.leiview{
			margin-bottom: 20rpx;
			display: flex;
			flex-direction: column;
			background-color: #fff;
			padding:25rpx 30rpx;
			.yuan{
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				color: #333333;
				display: inline-block;
				margin-left: 30rpx;
			}

			.leiitem{
				display: flex;
				flex-direction: row;
				align-items: center;
		        .name{
					font-family: PingFang SC;
					font-weight: bold;
					font-size: 30rpx;
					color: #444444;
				}
			}
			.xing{
				font-weight: bold;
				font-size: 30rpx;
				color: #FB1515;
				display: inline-block;
				margin-left: 6rpx;
			}
			.col{
				display: flex;
				flex-direction: column;
				align-items: flex-start;

			}
			.buzhou{
				font-weight: bold;
				font-size: 28rpx;
				color: #444444;
			}
			.buview{
				margin-top: 20rpx;
				border-bottom: 1rpx solid #eee;
				margin-bottom: 20rpx;
				padding-bottom: 15rpx;
			}
			.buviewtwo{
				margin-top: 20rpx;
				// border-bottom: 1rpx solid #eee;
				margin-bottom: 20rpx;
				// padding-bottom: 15rpx;
			}
			.buview:last-child{
				// border-bottom: none;
			}
			.zuiduo{
				font-weight: 500;
				font-size: 24rpx;
				color: #999999;
				display: inline-block;
				margin-left: 10rpx;
			}
			.tuview{
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
				// margin-top: 30rpx;
				.tuitem{
					width: 200rpx;
					height: 200rpx;
					position: relative;
					border-radius: 10rpx;
					margin: 0 20rpx 20rpx 0;
					.addtu{
						position: absolute;
						width: 100%;
						height: 100%;
						border-radius: 10rpx;
					}
					.cha{
						background-color: rgba(0, 0, 0, 0.4);
						position: absolute;
						width: 100%;
						height: 100%;
						display: flex;
						align-items: center;
						justify-content: center;
						border-radius: 10rpx;
						z-index: 10;
						text{
							font-family: PingFang SC;
							font-weight: 500;
							font-size: 24rpx;
							color: #FFFFFF;
						}
						.shanicon{
							position: relative;
							width: 50rpx;
							height: 50rpx;
							// right: 20rpx;
							// top: 20rpx;
						}
					}
					
				}
			}

			.wenben{
				background: #F5F5F5;
				border-radius: 20rpx;
				padding: 30rpx;
				width: 100%;
				margin: 20rpx 0;
			}
			.jiavx{
				padding: 14rpx 20rpx;
				background: #EEEEEE;
				border-radius: 10rpx;
				margin-top: 30rpx;
				display: flex;
				align-items: center;
				flex-direction: row;
				.icon_wx{
					width: 32rpx;
					height: 32rpx;
					margin-right: 10rpx;
				}
				text{
					font-weight: 500;
					font-size: 28rpx;
					color: #666666;
				}
			}
			.renview{
				display: flex;
				flex-direction: column;
				.renitem{
					display: flex;
					flex-direction: row;
					align-items: center;
					flex-wrap: wrap;
					.biaoqian{
						padding: 13rpx 19rpx;
						background: #EEEEEE;
						border-radius: 10rpx;
						display: flex;
						flex-direction: row;
						align-items: center;
						margin: 0 15rpx 15rpx 0;
						position: relative;
						.boitem{
							position: absolute;
							width: 100%;
							height: 100%;
						}
						.facha{
							width: 24rpx;
							height: 24rpx;
							margin-left: 13rpx;
						}
						.biaoname{
							font-weight: 500;
							font-size: 28rpx;
							color: #666666;
							position: relative;
						}
					}

					.biaoqiantwo{
						padding: 15rpx 40rpx;
						background: #EEEEEE;
						border-radius: 10rpx;
						display: flex;
						flex-direction: row;
						align-items: center;
						margin: 0 15rpx 15rpx 0;
						position: relative;
						justify-content: center;
						.biaoname{
							font-weight: 500;
							font-size: 28rpx;
							color: #666666;
							position: relative;
						}
						.boitem{
							position: absolute;
							width: 100%;
							height: 100%;
							display: none;
						}
						.chagou{
							width: 31rpx;
							height: 31rpx;
							position: absolute;
							right: 0;
							bottom: 0;
							display: none;
						}
					}	
					.active{
						.boitem{
							display: inline-block;
						}
						.biaoname{
							color: #46B2F2;
						}
						.chagou{
							display: inline-block;
						}
					}
				}
				.fajia{
					width: 116rpx;
					height: 52rpx;
					margin-top: 20rpx;
				}
			}
			.hong{
				color: #FF4949 !important;
			}
			.oneitem{
				margin-bottom: 20rpx;
			}
			.shu{
				display: inline-block;
				width: 8rpx;
				height: 30rpx;
				background: linear-gradient(90deg, #0DBFFB, #198EFF);
				margin-right: 7rpx;
			}
			.twoinput{
				background: #F8F8F8;
				border-radius: 6rpx;
				padding: 10rpx 20rpx;
			}
			.xuan{
				font-weight: bold;
				font-size: 30rpx;
				color: #0DBEFB;
			}
			.nav_icon_back{
				margin-left: 20rpx;
				width: 24rpx;
				height: 24rpx;
			}
			.addbuzhou{
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 10rpx 20rpx;
				border-radius: 10rpx;
				border: 2rpx solid #EBEBEB;
				margin-left: auto;
				font-weight: 500;
				font-size: 30rpx;
				color: #444444;
			}
		}
	}
	.ml{
		margin-left: auto;
	}

	.botview {
	height: 120rpx;
	background: #FFFFFF;
	width: 100%;
	position: fixed;
	bottom: 0;
	display: flex;
	flex-direction: row;
	align-items: center;
	z-index: 10;
	border-top: 1rpx solid #eee;
	padding: 30rpx;


	.botleft {
		width: 20%;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;

		.icon_fenxiang {
			width: 44rpx;
			height: 44rpx;

		}

		text {
			font-size: 18rpx;
			font-family: PingFang SC;
			font-weight: 400;
			color: #333333;
		}
	}

	.jinprice{
		font-weight: bold;
		font-size: 30rpx;
		color: #444444;
	}
	.jinnum{
		color: #F11B1B;
		font-size: 35rpx;
	}
	.lianxi {
		margin-left: auto;
		width: 240rpx;
		height: 88rpx;
		background: linear-gradient(-82deg, #4BB6F0, #1D8DFD);
		border-radius: 44rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-weight: 500;
		font-size: 28rpx;
		color: #FFFFFF;
	}
	
}
	
.xieyi{
	display: flex;
	margin: 50rpx 30rpx;
	flex-direction: row;
	align-items: center;
	.chagou{
		width: 40rpx;
		height: 40rpx;
		margin-right: 10rpx;
	}
	.tyiname{
		font-weight: 500;
		font-size: 26rpx;
		color: #666666;
	}
	.xiename{
		color: #1F8FFD;
	}
}
</style>
